package com.bys.admin.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bys.admin.system.entity.SysDept;
import com.bys.response.R;
import com.bys.admin.system.service.ISysDeptService;
import com.bys.vo.PageVo;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bys
 * @since 2025-01-23
 */
@Tag(name = "部门接口")
@RestController
@RequestMapping("/system/sys-dept")
public class SysDeptController {

    @Resource
    private ISysDeptService sysDeptService;
    @GetMapping("/simple-list")
    @Operation(summary="查询全部部门")
    public  R<List<SysDept>>  simpleList(){
        List<SysDept> list = sysDeptService.list();
        return R.success(list);
    }
    @Operation(summary="列表查询角色")
    @GetMapping(value = "/page")
    public R<Page<SysDept>> page(PageVo pageVo){
        Page<SysDept> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        Page<SysDept> data = sysDeptService.page(page);
        return R.success(data);
    }
    @Transactional(rollbackFor = Exception.class)
    @Operation(summary="保存部门")
    @PostMapping("/save")
    public R save(@RequestBody SysDept sysDept){
        sysDept.setCreateBy(1L);
        sysDeptService.save(sysDept);
        return R.success();
    }
    @Transactional(rollbackFor = Exception.class)
    @Operation(summary="修改部门")
    @PostMapping("/update")
    public R update(@RequestBody SysDept sysDept){
        sysDept.setUpdateBy(1L);
        sysDept.setUpdateTime(LocalDateTime.now());
        sysDeptService.updateById(sysDept);
        return R.success();
    }


}
